package com.isc.InetAddressAPI;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class test {
    public static void main(String[] args) throws UnknownHostException {
        //1.获取本机InetAddress对象
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost);

        //2.根据指定主机名获取InetAddress对象
        InetAddress hostName = InetAddress.getByName("雾");
        System.out.println(hostName);

        //3.根据域名返回InetAddress对象
        InetAddress baidu = InetAddress.getByName("www.baidu.com");
        System.out.println(baidu);

        //4.根据InetAddress对象 ，获取对应ip地址
        String hostAddress = baidu.getHostAddress();
        System.out.println(hostAddress);
        //获取域名
        String hostName1 = baidu.getHostName();
        System.out.println(hostName1);

    }
}
